package com.srit.identify.controller;

import com.srit.identify.common.IResponse;
import com.srit.identify.entity.IdentifyInfo;
import com.srit.identify.service.IIdentifyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Base64;

@RestController
public class IdentifyController {
    @Resource
    private IIdentifyService identifyService;

    @PostMapping("/identify")
    public IResponse identify(@RequestBody IdentifyInfo identifyInfo){
        return IResponse.success(identifyService.identify(identifyInfo));
    }

    @PostMapping("/identify_test")
    public IResponse identify_test(IdentifyInfo identifyInfo,@RequestParam("file") MultipartFile file) {
        try {
            byte[] bytes = file.getBytes();
            String s = Base64.getEncoder().encodeToString(bytes);
            identifyInfo.setPicData(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return this.identify(identifyInfo);
    }
}
